const commander = require('commander');
const { version } = require('../package.json');

// 命令
const actions = [
  {
    name: 'create',
    alias: 'c',
    description: 'create a new document',
    example: ['doc-cli create <document-name>'],
  },
  // *防止用户乱输命令
  {
    name: '*',
    alias: '',
    description: 'command not found',
    example: [],
  },
];

let exampleArr = [];
actions.forEach(item => {
  const { name, alias, description, example } = item;
  example.forEach(i => {
    exampleArr.push('  ' + i);
  });
  commander
    .command(name)
    .alias(alias)
    .description(description)
    .action(() => {
      const param = process.argv.slice(3);
      require(`./command/${name}`)(...param);
    });
});

// 解析用户传来的参数，是"version"的话执行version
commander.version(version).parse(process.argv);
